package java8_26.chongwu;

/**
 * @author oldliu
 * @since 1.0
 */
public /*final*/ class Dog extends Pet {
    private String strain;//类别
    public Dog(String name, String sex, int health, int love) {
        super(name, sex, health, love);
        System.out.println("狗的构造方法结束");
    }
    public Dog(String name, String sex, int health, int love,String s) {
        super(name, sex, health, love);
        this.strain=s;

    }
    public String getStrain() {
        return strain;
    }

    public void setStrain(String strain) {
        this.strain = strain;
    }
    //加一个方法
    public void catchMouse(){
        System.out.println(getName()+"正在抓老鼠！");
    }

    @Override//重写父类的方法
    public final void eat() {
        //super.eat();
        System.out.println(super.getName()+"在吃狗粮！");
    }

    @Override
    public  void print() {
        super.print();
        System.out.println("类别是"+strain);
    }

    @Override
    public String toString() {
        return super.toString()+",类别是："+strain;
    }
    //定标准
    @Override
    public boolean equals(Object obj) {
        //obj把变成Dog
        if(obj instanceof Dog){//obj其实是个Dog类的对象
            Dog t=(Dog)obj;//强转！
            if(this.name==null &&t.name==null)
                return true;
            else if(this.name==null){
                return false;
            }
            return this.name.equals(t.name);//名字相同，就是相等
        }
        return false;
    }
}
